#ifndef U2StringConverter_H
#define U2StringConverter_H


#include "U2PreRequest.h"
#include "U2StringUtil.h"



U2EG_NAMESPACE_BEGIN



class _U2Share U2StringConverter
{
public:
    /** Converts a u2real to a U2String. */
    static U2String toString(u2real val, unsigned short precision = 6, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );

    /** Converts an int to a U2String. */
    static U2String toString(int val, unsigned short width = 0, 
        char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );

#if U2_ARCH_TYPE == U2_ARCHITECTURE_64 || U2_PLATFORM == U2_PLATFORM_APPLE || U2_PLATFORM == U2_PLATFORM_APPLE_IOS
    /** Converts an unsigned int to a U2String. */
    static U2String toString(unsigned int val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );

    /** Converts a size_t to a U2String. */
    static U2String toString(size_t val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );

#   if U2_COMPILER == U2_COMPILER_MSVC
    /** Converts an unsigned long to a U2String. */
    static U2String toString(unsigned long val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );
#   endif

#else

    /** Converts a size_t to a U2String. */
    static U2String toString(size_t val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );

    /** Converts an unsigned long to a U2String. */
    static U2String toString(unsigned long val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );
#endif

    /** Converts a long to a U2String. */
    static U2String toString(long val, 
        unsigned short width = 0, char fill = ' ', 
        std::ios::fmtflags flags = std::ios::fmtflags(0) );

    /** Converts a boolean to a U2String. 
    @param yesNo If set to true, result is 'yes' or 'no' instead of 'true' or 'false'
    */
    static U2String toString(bool val, bool yesNo = false);

    /** Converts a U2StringVector to a string.
    @remarks
        Strings must not contain spaces since space is used as a delimiter in
        the output.
    */
    static U2String toString(const U2StringVector& val);

    /** Converts a U2String to a u2real. 
    @returns
        defaultValue if the value could not be parsed, otherwise the u2real version of the U2String.
    */
    static u2real parseReal(const U2String& val, u2real defaultValue = 0);

    /** Converts a U2String to a whole number. 
    @returns
        defaultValue if the value could not be parsed, otherwise the numeric version of the U2String.
    */
    static int parseInt(const U2String& val, int defaultValue = 0);

    /** Converts a U2String to a whole number. 
    @returns
        defaultValue if the value could not be parsed, otherwise the numeric version of the U2String.
    */
    static unsigned int parseUnsignedInt(const U2String& val, unsigned int defaultValue = 0);

    /** Converts a U2String to a whole number. 
    @returns
        defaultValue if the value could not be parsed, otherwise the numeric version of the U2String.
    */
    static long parseLong(const U2String& val, long defaultValue = 0);

    /** Converts a U2String to a whole number. 
    @returns
        defaultValue if the value could not be parsed, otherwise the numeric version of the U2String.
    */
    static unsigned long parseUnsignedLong(const U2String& val, unsigned long defaultValue = 0);

    /** Converts a U2String to a boolean. 
    @remarks
        Returns true if case-insensitive match of the start of the string
		matches "true", "yes" or "1", false otherwise.
    */
    static bool parseBool(const U2String& val, bool defaultValue = 0);

    /** Pareses a U2StringVector from a string.
    @remarks
        Strings must not contain spaces since space is used as a delimiter in
        the output.
    */
    static U2StringVector parseStringVector(const U2String& val);

    /** Checks the U2String is a valid number value. */
    static bool isNumber(const U2String& val);

};



U2EG_NAMESPACE_END

#endif
